package com.campus.common.config;

import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.BlockAttackInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MybatisPlusConfig {

    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor(){
        //该对象用于配置mybatis Plus的拦截器
        MybatisPlusInterceptor interceptor=new MybatisPlusInterceptor();
        //该对象用于实现分页功能
        PaginationInnerInterceptor innerInterceptor=new PaginationInnerInterceptor();
        //对分页插件的溢出总页数后是进行处理
        innerInterceptor.setOverflow(true);
        //分页
        interceptor.addInnerInterceptor(innerInterceptor);
        //乐观锁
        interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
        //防止全局修改和删除
        interceptor.addInnerInterceptor(new BlockAttackInnerInterceptor());
        return interceptor;
    }
}
